package com.example.boot3.controller;


import com.alibaba.excel.EasyExcel;
import com.example.boot3.model.Insurance;
import com.example.boot3.model.Repair;
import com.example.boot3.model.Violation;
import com.example.boot3.service.InsuranceService;
import com.example.boot3.service.RepairService;
import com.example.boot3.util.JsonData;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
public class InsuranceController {
    @Autowired
    private InsuranceService insuranceService;
    @GetMapping("insurance_info")
    public JsonData getRepairList(){
        List<Insurance> insuranceList  = insuranceService.getInsuranceList();
        return JsonData.buildSuccess(insuranceList);
    }

    @PostMapping("register_insurance")
    public JsonData registerRepair(@RequestBody Insurance insurance){
        Integer result = insuranceService.registerInsurance(insurance);
       return JsonData.buildSuccess(result);
    }
    @GetMapping("insurance/export")
    public void Export(HttpServletResponse response) throws IOException {
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-Disposition", "attachment; filename=insurances.xlsx");
        List<Insurance> data = insuranceService.getInsuranceList();
        EasyExcel.write(response.getOutputStream(), Insurance.class).sheet("保险信息").doWrite(data);
    }
}
